package com.property.manage.controller.flowingWater;

import com.property.manage.enums.WalletType;
import com.property.manage.service.flowingWater.WalletService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;

/**
 * 描述
 *
 * @author lwb
 * @since 2020/7/15
 */
@Api(tags = "钱包")
@RestController
@RequestMapping("/wallet")
@AllArgsConstructor
@Validated
public class WalletController {


    @Autowired
    private WalletService walletService;


    @ApiOperation("预存费用-测试")
    @PostMapping("/add")
    public void add(
                    @ApiParam("金额") @RequestParam(value = "money") @NotNull(message = "金额") BigDecimal money,
                    @ApiParam("楼栋id") @RequestParam(value = "buildingId") @NotNull(message = "业主id不能为空") Integer villageId

    ) {
        walletService.deposit(villageId,money, null);
    }

    @ApiOperation("扣除预存费用")
    @PostMapping("/updateExpenditure")
    public BigDecimal updateExpenditure(
            @ApiParam("金额") @RequestParam(value = "money") @NotNull(message = "金额") BigDecimal money,
            @ApiParam("楼栋id") @RequestParam(value = "buildingId") @NotNull(message = "楼栋id不能为空") Integer villageId

    ) {
       return walletService.updateExpenditure(villageId,money, null);
    }

    @ApiOperation("找零转存")
    @PostMapping("/changeDeposit")
    public BigDecimal updateIncome(
            @ApiParam("金额") @RequestParam(value = "money") @NotNull(message = "金额") BigDecimal money,
            @ApiParam("楼栋id") @RequestParam(value = "buildingId") @NotNull(message = "楼栋id不能为空") Integer villageId

    ) {
       return walletService.changeDeposit(villageId,money, null);
    }

    @ApiOperation("根据楼栋id查找余额")
    @GetMapping("/findBalance")
    public BigDecimal findBalance(
            @ApiParam("楼栋id") @RequestParam(value = "buildingId") @NotNull(message = "楼栋id不能为空") Integer villageId,  WalletType walletType

    ) {
        return walletService.findBalance(villageId, walletType);
    }

    /*@ApiOperation("修改")
    @PostMapping("/update")
    public void update(@RequestParam(value = "id") @NotNull(message = "id不能为空") Integer id,
                       @ApiParam("金额") @RequestParam(value = "money") @NotNull(message = "金额") BigDecimal money,
                       @ApiParam("下次缴费时间") @RequestParam(value = "number", required = false) LocalDate nextTime,
                       @ApiParam("关联id(物业管理id或者租金管理id)") @RequestParam(value = "relationId", required = false) Integer relationId,
                       @ApiParam("减免金额") @RequestParam(value = "deduction") @NotNull(message = "减免金额不能为空") BigDecimal deduction,
                       @ApiParam("收费名目") @RequestParam(value = "listOfCharges") @NotBlank(message = "收费名目不能为空") String listOfCharges,
                       @ApiParam("收费类型") @RequestParam(value = "chargeType") @NotNull(message = "收费类型不能为空") Integer chargeType,
                       @ApiParam("付款方") @RequestParam(value = "payer") @NotBlank(message = "付款方不能为空") String payer,
                       @ApiParam("收款方") @RequestParam(value = "payee") @NotBlank(message = "付款方不能为空") String payee,
                       @ApiParam("收款类型 1收入 2支出") @RequestParam(value = "type") @NotNull(message = "收款类型不能为空") Integer type,
                       @ApiParam("收款时间") @RequestParam(value = "paymentTime") @NotNull(message = "收款时间不能为空") LocalDate paymentTime
    ) {
        flowingWaterService.update(id, money, nextTime, relationId, listOfCharges, chargeType, payer, payee, type, paymentTime, deduction);
    }
*/
    @ApiOperation("删除")
    @PostMapping("/delete")
    public void delete(@ApiParam("楼栋id") @RequestParam("id") @NotNull(message = "id为空") Integer id) {
        walletService.delete(id);
    }



}
